package com.showgood.view.mediator {
	import com.showgood.config.PopupConfig;
	import com.showgood.config.SangoConst;
	import com.showgood.core.AbstractMediator;
	import com.showgood.core.GameEvent;
	import com.showgood.core.NotificationDispatcher;
	import com.showgood.core.NotificationEvent;
	import com.showgood.model.GameViewProxy;
	import com.showgood.model.PreloadProxy;
	import com.showgood.util.GameUtil;
	import com.showgood.util.MapElem;
	import com.showgood.util.Path2I;
	import com.showgood.view.component.MarchPath;
	import com.showgood.vo.ArmyVO;
	import com.showgood.vo.CityVO;
	import com.showgood.view.CityDialog;
	import flash.events.IEventDispatcher;
	
	/**
	 * 确认窗口的处理
	 * @author bianpeng
	 */
	public class FirmSlidderMediator extends AbstractMediator {
		public function FirmSlidderMediator(viewComponent:Object = null) {
			super(viewComponent);
		}
		override public function onRegister():void {
			var d:IEventDispatcher = (getViewComponent() as IEventDispatcher);
			d.addEventListener(SangoConst.CANCEL_WINDOW, onCancelCreateArmy);
			d.addEventListener(SangoConst.OK_WINDOW, onOkCreateArmy);
		}
		override protected function setupNotifactionHandler(dispatcher:NotificationDispatcher):void {
			dispatcher.addHandler(SangoConst.SELECT_CITY_DISTINATION, onSelectCity);
			dispatcher.addHandler(SangoConst.SELECT_ARMY_DISTINATION, onSelectArmy);
		}
		private function onSelectCity(event:NotificationEvent):void {
			var _src:CityVO = (sangoFacade.retrieveMediatorByType(CityDialogMediator).getViewComponent() as CityDialog).city;
			var _dst:CityVO = event.data as CityVO;
			var _p:GameViewProxy = sangoFacade.retrieveProxyByType(GameViewProxy) as GameViewProxy;
			_p.updateMarchPathToCity(_src, _dst);
		}
		private function onSelectArmy(event:NotificationEvent):void {
			var _src:CityVO = (sangoFacade.retrieveMediatorByType(CityDialogMediator).getViewComponent() as CityDialog).city;
			var _dst:ArmyVO = event.data as ArmyVO;
			var _p:GameViewProxy = sangoFacade.retrieveProxyByType(GameViewProxy) as GameViewProxy;
			_p.updateMarchPathToArmy(_src, _dst);
		}
		private function onCancelCreateArmy(event:GameEvent):void {
			var gameViewProxy:GameViewProxy = sangoFacade.retrieveProxyByType(GameViewProxy) as GameViewProxy;
			gameViewProxy.finishCreateArmy(false);
		}
		private function onOkCreateArmy(event:GameEvent):void {
			var gameViewProxy:GameViewProxy = sangoFacade.retrieveProxyByType(GameViewProxy) as GameViewProxy;
			gameViewProxy.finishCreateArmy(true);
			// 然后退掉所有的窗口
			sangoFacade.popups.popWindow(PopupConfig.ALL_WINDOW);
		}
	}
}

